/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

    var map;
    var geocoder;
    var address;


    function initialize() {
      map = new GMap2(document.getElementById("carte"));
      map.setCenter(new GLatLng(48.98404743872055, 2.226276397705078), 15);
      map.addControl(new GLargeMapControl);
      GEvent.addListener(map, "click", getAddress);
      geocoder = new GClientGeocoder();
    }

    function getAddress(overlay, latlng) {
      if (latlng != null) {
        address = latlng;
        geocoder.getLocations(latlng, showAddress);
      }
    }

    function showAddress(response) {
      map.clearOverlays();
      if (!response || response.Status.code != 200) {
        alert("Status Code:" + response.Status.code);
      } else {
        place = response.Placemark[0];
        point = new GLatLng(place.Point.coordinates[1],
                            place.Point.coordinates[0]);
        marker = new GMarker(point);
        map.addOverlay(marker);

        document.getElementById("adr").value =place.address;
        document.getElementById("lat").value = place.Point.coordinates[0];
        document.getElementById("lng").value = place.Point.coordinates[1];        
        marker.openInfoWindowHtml(place.address );
      }
    }

    function verif_formulaire(){
         if(document.formulaire.nom.value == "")
         {
            alert("Veuillez entrer un nom!");
            document.formulaire.nom.focus();
            exit();
         }

         if(document.formulaire.adr.value == "")
         {
            alert("Veuillez entrer une adresse!");
            document.formulaire.adr.focus();
            exit();
         }

         if(document.formulaire.lat.value == "")
         {
            alert("Veuillez entrer une latitude!");
            document.formulaire.lat.focus();
            exit();
         }

         if(document.formulaire.lng.value == "")
         {
            alert("Veuillez entrer une longitude!");
            document.formulaire.lng.focus();
            exit();
         }
    }

    function montrerAdresse(adresse) {
      if (geocoder) {
        geocoder.getLocations(adresse,showAddress);
      }
    }
